from fastapi import APIRouter, Request
from re_common.baselibrary.utils.core.mlamada import bools_string
from re_common.baselibrary.utils.core.requests_core import MsgCode

from apps.core.m_route import ContextIncludedRoute
from apps.core.return_info import ReturnInfo
from apps.crawler_platform.core_platform.g_model import InputPlatformModel, JournalArticleMode
from apps.crawler_platform.etl_platform.etl_remote_ref import EtlRemoteRef

router = APIRouter(route_class=ContextIncludedRoute)


@router.post("/remote_ref")
async def remote_ref(request: Request, input: InputPlatformModel[JournalArticleMode]):
    """
    期刊本地etl
    :return:
    """
    return_info = ReturnInfo()
    down = EtlRemoteRef(request, input)
    bools, err_info = await down.my_task()
    step_info = down.step_info
    return_info.status = bools_string(bools)
    if bools:
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = step_info
        return_info.data = ""
    else:
        return_info.msg_code = MsgCode.API_FAIL_CODE
        return_info.msg = step_info
        return_info.data = {"err_info": err_info}
    return return_info.todict()
